import { defineStore } from "pinia";
import { store } from "@/store";
// import { ClusterT, AppInstallT, IssueAppForm } from "@/api/cluster";
import { addClusterDto } from "@/api/vap/cluster";
export const useVaStore = defineStore({
  id: "veapp",
  state: () => ({
    // 集群添加和修改的模态框相关属性
    CurrrentCluster: {} as addClusterDto,
    title: "",
    isAdd: true,
    dialogVisible: false,
    // 发布应用的第一个模态框组件中的数据
    // clusterInfo: {} as ClusterT, //两个模态框共享的数据，需要知道自己当前是那个集群
    // issueAppDialogOne: false,
    // appList: [] as AppInstallT[],
    // multipleSelection: [] as AppInstallT[],
    // // 发布应用的第二个模态框组件中的数据
    // issueAppDialogTwo: false,
    // issueAppForm: {} as IssueAppForm,
    // checkAppList: [] as AppInstallT[],
    // 发布应用的第三个模态框组件中的数据
    issueAppDialogThree: false,
    deptTree: [],
    selectDeptList: [], //每一个元素都是一个tree node 节点对象
    selectUserList: [], // 每个元素都是一个 {label: '周磊', value: '1651229270673985536'}
    showUserDesktopAppList: false, // 控制用户桌面页面的模态框显示
    openAppId: "", // 复用会话打开应用时跨组件传递的应用ID
    sendInstructDialog: false,
    instructRowSessionId: ""
  }),
  actions: {
    /** 存储用户名 */
    ShowdialogForAddCluster() {
      this.CurrrentCluster = {
        clusterId: "0",
        name: "",
        cpuThreshold: 80,
        memoryThreshold: 80,
        timeOutAction: 1,
        maxSessionTime: 120,
        maxTimeOutTime: 50,
        clusterType: 1
      };
      this.title = "添加";
      this.isAdd = true;
      this.dialogVisible = true;
    },
    /** 存储角色 */
    // ShowdialogForEditCluster(r: ClusterT) {
    //   this.CurrrentCluster = {
    //     clusterId: r.clusterId,
    //     name: r.name,
    //     cpuThreshold: r.cpuThreshold * 100,
    //     memoryThreshold: r.memoryThreshold * 100,
    //     timeOutAction: r.timeOutAction,
    //     maxSessionTime: r.maxSessionTime,
    //     maxTimeOutTime: r.maxTimeOutTime,
    //     clusterType: r.clusterType
    //   };
    //   this.title = "修改";
    //   this.isAdd = false;
    //   this.dialogVisible = true;
    // },
    // // 处理第一个应用发布模态框 中的表格选中
    // handleSelectionChange(val: AppInstallT[]) {
    //   this.multipleSelection = val;
    // },
    //发布应用的第三个模态框中的全局应用开关变化时触发的方法
    handleIssueAppSwitchChange() {
      this.selectDeptList = [];
      this.selectUserList = [];
    },
    depIdCheck(nodeObj: any, selectedObj: any) {
      console.log(nodeObj, selectedObj);
    },
    handleNodeClick(data: any) {
      console.log(data);
    },
    openAppForReuse(id: string) {
      console.log(id);
      this.openAppId = id;
    }
  }
});

export function useVaStoreHook() {
  return useVaStore(store);
}
